package com.lovo.service.impl;

import com.lovo.cloud.model.dto.MovieOrderDTO;
import com.lovo.service.GetOrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author luo
 * @description
 * @date 2020/12/3 20:49
 */
@Service
public class GetOrderServiceImpl implements GetOrderService {

    @RabbitListener(queues = {"j177_point","j177_point22","deadQueue"})
    @Override
    public void getOrder(MovieOrderDTO movieOrderDTO, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {

        try {
            //tag-队列中数据的标记，flase-非批量确认

            //不确认，false不批量处理，true,不消费，继续保留在队列中
//           channel.basicNack(tag,false,true);
            System.out.println(movieOrderDTO.getMovieName());
//                int b =  10 /0;
               channel.basicAck(tag,false);
        } catch (IOException e) {

            e.printStackTrace();
        }
    }

    @RabbitListener(queues = "j177_topic")
    @Override
    public void getString(String string) {
        System.out.println(string);
    }
}
